(async () => {
  var mongoose = require('mongoose');
  const Record = require('./schema/Record')
  mongoose.connect('mongodb://user1:123qwe@111.231.55.85:27017/hospital', { useNewUrlParser: true });
  
  let chiefComplaint = {
    data: [
      {
        part: ['C.100.100067'],        
        symptom: 'C.101.100001',
        character: 'C.102.100001',
        level: 'C.103.tiny',
        time: 35,
        unit: 'C.105.day',        
        chosen: true
      },
      {
        part: ['C.100.100064'], 
        symptom: 'C.101.100044',
        character: 'C.102.100005',
        level: 'C.103.serious',
        time: 5,
        unit: 'C.105.year',
        chosen: true,
        follow: [
          {
            symptom: 'C.101.100028'
          }
        ]
      },
      {
        part: ['C.100.100035'],
        symptom: 'C.101.100050',
        character: 'C.102.100003',
        level: 'C.103.light',        
        time: 2,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100051'],
        symptom: 'C.101.100017',
        character: 'C.102.100001',
        level: 'C.103.tiny',
        time: 8,
        unit: 'C.105.month',
        chosen: true
      },
      {
        part: ['C.100.100068'],
        symptom: 'C.101.100015',
        character: 'C.102.100002',
        level: 'C.103.medium',
        time: 6,
        unit: 'C.105.week',
        chosen: true
      },
      {
        part: ['C.100.100038'],        
        symptom: 'C.101.100046',
        character: 'C.102.100004',
        level: 'C.103.light',
        time: 50,
        unit: 'C.105.hour',        
        chosen: true
      },
      {
        part: ['C.100.100001'], 
        symptom: 'C.101.100050',
        character: 'C.102.100010',
        level: 'C.103.medium',
        time: 6,
        unit: 'C.105.week',
        chosen: true,
        follow: [
          {
            symptom: 'C.101.100028'
          }
        ]
      },
      {
        part: ['C.100.100014'],
        symptom: 'C.101.100044',
        character: 'C.102.100001',
        level: 'C.103.light',        
        time: 12,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100022'],
        symptom: 'C.101.100058',
        character: 'C.102.100011',
        level: 'C.103.serious',
        time: 3,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100029'],
        symptom: 'C.101.100012',
        character: 'C.102.100014',
        level: 'C.103.serious',
        time: 4,
        unit: 'C.105.day',
        chosen: true
      },
      {
        part: ['C.100.100019'],
        symptom: 'C.101.100012',
        character: 'C.102.100005',
        level: 'C.103.medium',
        time: 5,
        unit: 'C.105.day',
        chosen: true
      },
      {
        part: ['C.100.100066'],
        symptom: 'C.101.100001',
        character: 'C.102.100017',
        level: 'C.103.medium',
        time: 8,
        unit: 'C.105.week',
        chosen: true
      }        
    ],
    mainType: [
      // {
      //   name: '肺炎',
      //   type: ['病毒性肺炎','真菌性肺炎','细菌性肺炎','支原体肺炎','衣原体肺炎']
      // }
    ],
  }
  let patientInfo = {
    patientName: {
      label: '姓名',
      value: '李洪',
      chosen: true
    },
    medicareId: {
      label: '医保卡号',
      value: 'D23123855',
      chosen: true
    },
    sex: {
      label: '性别',
      value: '男',
      chosen: true
    },
    age: {
      label: '年龄',
      value: 44,
      chosen: true
    },
    temperature: {
      label: '体温',
      value: 39,
      chosen: true
    },
    bloodPressure: {
      label: '血压',
      value: {
        sbp: 116,
        dbp: 72 
      },
      chosen: true
    },
    heartRate: {
      label: '心率',
      value: 86,
      chosen: true
    },
    weight: {
      label: '体重',
      value: 64,
      chosen: false
    },
    height: {
      label: '身高',
      value: 172,
      chosen: false
    },
    bmi: {
      label: 'BMI指数',
      value: 26,
      chosen: false
    },
    breath: {
      label: '呼吸',
      value: 16,
      chosen: false
    },
    marriage: {
      label: '婚孕',
      value: '已婚',
      chosen: false
    },
    pulse: {
      label: '脉搏',
      value: 76,
      chosen: false
    },
    spo2: {
      label: '氧饱和度',
      value: 95,
      chosen: false
    }
  }
  let data = {
    name: '肺炎1型',
    remark: '备注zzzzz',
    patientInfo: patientInfo,
    chiefComplaint: chiefComplaint,
    HPI: {
      situation: {
        ifNull: false,
        date: '2017-12-13',
        cause: ['tired', 'alcohol']
      },
      medication: {
        ifNull: false,
        data: [
          {
            _type: '100001',
            name: '100001',
            rate: '100003',
            metering: '10g',
            duration: '3天',
            effect: '100003'
          }
        ]
      },
      unusual: {
        ifNull: false,
        data: [{
          hospital: '嘉兴市第一人民医院',
          name: '血检',
          dateTime: '2019-01-01 12:09:07',
          data: [{          
            itemCode: 'G.100.100001',
            itemName: '血沉',
            resultValue: 11.5,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100002',
            itemName: '血常规',
            resultValue: 7.48,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100003',
            itemName: '尿沉渣定量',
            resultValue: 1.5,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100004',
            itemName: '尿常规',
            resultValue: 0.52,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100005',
            itemName: '粪常规检查',
            resultValue: 78.96,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100012',
            itemName: '血浆D-二聚体测定（D-Dimer）',
            resultValue: 3.5,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100014',
            itemName: '红细胞流变特性',
            resultValue: 11.5,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100015',
            itemName: '全血粘度测定',
            resultValue: 1.73,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100016',
            itemName: '血浆粘度测定',
            resultValue: 7.48,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100017',
            itemName: '血清总蛋白测定（TP)',
            resultValue: 1.5,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100018',
            itemName: '血清白蛋白测定（ALB)',
            resultValue: 0.52,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100019',
            itemName: '血清前白蛋白测定（PAB)',
            resultValue: 78.96,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100025',
            itemName: '餐后2小时血糖',
            resultValue: 6.35,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100037',
            itemName: '血清氯测定',
            resultValue: 2.58,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100055',
            itemName: '血清间接胆红素测定',
            resultValue: 17.69,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100064',
            itemName: '血清乳酸脱氢酶测定',
            resultValue: 13.25,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100077',
            itemName: '血清维生素B12测定（VB12）',
            resultValue: 19.52,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100098',
            itemName: '血浆D-二聚体测定（D-Dimer）',
            resultValue: 11.25,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100116',
            itemName: '甲状腺球蛋白抗体测定(TGAb)',
            resultValue: 9.47,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.100.100146',
            itemName: '复合前列腺特异性抗原测定',
            resultValue: 6.78,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100043',
            itemName: '双下肢血管MRA',
            resultValue: 13.25,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100069',
            itemName: '双源CT上腹部增强测定',
            resultValue: 32.58,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100079',
            itemName: '关节彩超检查',
            resultValue: 15.67,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100086',
            itemName: '双侧腋下淋巴彩超检查',
            resultValue: 24.36,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100092',
            itemName: '球后全部血管彩超检查',
            resultValue: 4.65,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100093',
            itemName: '颈动脉彩超检查',
            resultValue: 5.39,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100094',
            itemName: '双侧椎动脉彩超检查',
            resultValue: 4.29,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100095',
            itemName: '门静脉彩超检查',
            resultValue: 64.55,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100096',
            itemName: '胸腹主动脉彩超检查',
            resultValue: 1.36,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100097',
            itemName: '双侧下肢动脉彩超检查',
            resultValue: 3.47,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100098',
            itemName: '双肾及肾血管彩超检查',
            resultValue: 8.69,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100099',
            itemName: '腔内彩超检查',
            resultValue: 14.36,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100103',
            itemName: '左心功能测定',
            resultValue: 2.26,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100107',
            itemName: '心内膜自动边缘检测（AQ）',
            resultValue: 12.58,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100128',
            itemName: '肺通气功能检查',
            resultValue: 3.68,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100134',
            itemName: '遥测心电监护',
            resultValue: 9.98,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100135',
            itemName: '平板运动试验',
            resultValue: 22.36,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          },
          {
            itemCode: 'G.101.100143',
            itemName: '尿流动力学检测',
            resultValue: 15.42,
            startRange: 0.8,
            endRange: 4,
            resultUnit: 'mg'
          }]
        }]     
      }
    },
    pastHistory: {
      personal: {
        ifNull: false,
        data: ['吸烟', '熬夜', '精神创伤']
      },
      family: {
        ifNull: false,
        data: [{
          disease: '100010',
          sibship: '100002',
          age: '0'
        }]
      },
      surgery: [
        {
          ifNull: false,
          data: [{
            name: '手术名称',
            ID: 'IDXXX',
            hospital: '浙江省第一人民医院',
            dateTime: '2014-11-16'
          }]
        }
      ],
      allergic: {
        ifNull: false,
        data: [{
          source: '阿司匹林',
          reaction: '100001',
          level: '100001'
        }]
      },
      menstrual: {
        ifNull: false,
        firstAge: 12,
        cycle: 27,
        duration: 27,
        lastDate: '2018-01-01',
        endDate: '2018-01-01',
        endAge: 50
      },
      chronic: {
        ifNull: false,
        data: [{
          disease: '100008',
          duration: 3,
          durationUnit: 'quarter',
          level: '100003'
        }]
      }
    },
    PE: [
      {
        name: '生命体征',
        value: null,
        _type: 'children',
        max: null,
        unit: null,
        children: [
          {
            name: '体温',
            value1: '37.5',
            value2: null,
            valueNum: '1',
            unit: '℃'
          },
          {
            name: '脉搏',
            value1: '120',
            value2: null,
            valueNum: '1',
            unit: '次/min'
          },
          {
            name: '呼吸',
            value1: '60',
            value2: null,
            valueNum: '1',
            unit: '次/min'
          },
          {
            name: '血压',
            value1: '127',
            value2: '69',
            valueNum: '2',
            unit: 'mmHg'
          }
        ]
      },
      {
        name: '头部',
        value: 2,
        _type: 'slider',
        max: 6,
        unit: '级'
      },
      {
        name: '其他',
        value: '',
        _type: 'textarea',
      }
    ],
    checkout: {
      checking: []
    },
    diagnosis: [
      {
        diseaseCode: '',
        diseaseName: '肺水肿',
        state: 'certain'
      },
      {
        diseaseCode: '',
        diseaseName: '肺炎',
        state: 'uncertain'
      }
    ]
  }
  data.templateId = '5c91e1d080ced771506aa844'
  data.templateOwner = '666001'
  data.templateOwnerName = '消化内科医疗组1'
  data.name = '肺炎1型-自己sss'
  data.patientInfo.patientId = 'br58ba345d4c7e'
  data.patientInfo.telephone = '13754564675'
  data.patientInfo.cardId = null
  data.patientInfo.birtplace = null
  data.patientInfo.birthday = '1965-12-30'
  data.patientInfo.vocation = 'C'
  data.patientInfo.address = '文三西路2号'
  data.datetime = '2019-03-17 00:00'
  data.doctor = '666001'
  data.doctorName = '消化内科主任'
  data.groups = [{
    groupId: 501,
    groupName: '消化内科医疗组1'
  }]
  data.dept = '810001'
  data.deptName = '消化内科'
  data.state = 'save'
  // 林朝玉2
  data.patientInfo.id = 'jz03d0f2d0d106'
  await new Record(data).save()
  // 李洪5
  data.patientInfo.id = 'jz127fe6ace0ce2'
  await new Record(data).save()
  // 骆锦红6
  data.patientInfo.id = 'jzabed16a6fbd9'
  await new Record(data).save()
  // 张晓雨7
  data.patientInfo.id = 'jzb9c48f4621391'
  await new Record(data).save()
  // let record = await Record.findOne({
  //   'templateId': '5c90a6ebcc70e82a8f127e75',
  //   'patientInfo.id': 'jzabed16a6fbd9',
  //   'state': 'save'
  // })
  // console.log(record)
  process.exit(0)
})()